<template>
	<view>
		<view class="mainpadding2">
			<view class="titletext bold hei_text margin_top">地区（省市）</view>
			<view class="mainpadding_top bghui radius flexbetween" @click="pickerdzshow=true">
				<input type="text" placeholder="请选择地区" class="hei_text main_size bold" disabled v-model="cityInfo.region">
				<u-icon name="arrow-right" color="#333" size="16"></u-icon>
			</view>
			<view class="margin_top" v-for="item in schoolList" :key="item.period">
				<view class="titletext bold hei_text margin_top">{{item.period_text}}</view>
				<view class="flexleft flex_wrap">
					<view class="screenbox margin_top flexcenter" v-for="ite in item.data" :key="ite.id" @click="checknj(ite)">
						<view :class="njInfo.id==ite.id?'itemscreenfocus':'itemscreen'">{{ite.name}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mainpadding_top">
			<view class="submitbtn" @click="submit">保存</view>
		</view>
		<pickercity :messageInfo="{pickerdzshow:pickerdzshow}" @surecity="surecity"></pickercity>
	</view>
	
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// 选择地区
				pickerdzshow:false,
				schoolList:[],
				njInfo:{
					name:"",
					id:"",
					period:"",
				},
				cityInfo:uni.getStorageSync("cityInfo"),
			}
		},
		onLoad() {
			this.getNj()
		},
		onShow() {
			let njInfo = uni.getStorageSync("njInfo")
			if(njInfo){
				this.njInfo = njInfo
			}
		},
		methods: {
			getNj(){
				httpRequest.request("/api/index/grade_show", 'GET', {
				}, false, false, true).then(res => {
					this.schoolList = res.data
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			checknj(item){
				this.njInfo = {
					name:item.name,
					id:item.id,
					period:item.period
				}
			},
			surecity(e) {
				this.pickerdzshow = false
				if(e){
					this.cityInfo = {
						region:e.provence + "/" + e.city,
						provence:e.provenceid,
						city:e.cityid
					}
				}
			},
			submit(){
				uni.setStorageSync("njInfo",this.njInfo)
				uni.setStorageSync("cityInfo",this.cityInfo)
				uni.$emit("changenj")
				httpRequest.toast("保存成功")
				setTimeout(()=>{
					uni.navigateBack(1)
				},1000)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.itemscreen {
		width: 200rpx;
		height: 65rpx;
		line-height: 65rpx;
		text-align: center;
		border-radius: 10rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333;
		background-color: #f5f5f5;
	}
	
	.itemscreenfocus {
			width: 200rpx;
			height: 65rpx;
			line-height: 65rpx;
			text-align: center;
			border-radius: 10rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #3478f5;
			background-color: #e6edf9;
			box-sizing: border-box;
			border: 1rpx solid #3478f5;
		}
</style>
